--Index IX_CREENI_JT_2 não encontrado.
\echo 'Criando Index IX_CREENI_JT_2'

CREATE OR REPLACE FUNCTION func_dropIndexElement() RETURNS void AS $$
DECLARE
    VCOUNT  INTEGER := 0;
BEGIN
  SELECT COUNT(*) INTO VCOUNT FROM pg_indexes WHERE indexname = 'ix_creeni_jt_2' AND schemaname = '<SCHEMA>';

      IF VCOUNT = 1 THEN
          DROP INDEX IX_CREENI_JT_2;
      END IF;
      RETURN;
END;

$$ LANGUAGE plpgsql;
SELECT func_dropIndexElement();
 DROP FUNCTION func_dropIndexElement();

CREATE OR REPLACE FUNCTION func_createIndexElement() RETURNS void AS $$
DECLARE
    VCOUNT  INTEGER := 0;
BEGIN
  SELECT COUNT(*) INTO VCOUNT FROM pg_indexes WHERE indexname = 'ix_creeni_jt_2' AND schemaname = '<SCHEMA>';

      IF VCOUNT = 0 THEN
          CREATE INDEX IX_CREENI_JT_2 ON <SCHEMA>.CREDENTIAL_ENTITY_ID (COD_CREDENTIAL ASC, COD_ENTITY ASC);
      END IF;
      RETURN;
END;

$$ LANGUAGE plpgsql;
SELECT func_createIndexElement();
 DROP FUNCTION func_createIndexElement();
